package com.citycloud.ccuap.tc.common.page;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("分页查询参数")
public class PageParameter {
	@ApiModelProperty("当前页，从0开始计算")
	private int start;

	public void setStart(int start) {
		this.start = start;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	@Override
    public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		if (!(o instanceof PageParameter)) {
			return false;
		}
		PageParameter other = (PageParameter) o;
		if (!other.canEqual(this)) {
			return false;
		}
		if (getStart() != other.getStart()) {
			return false;
		}
		if (getLimit() != other.getLimit()) {
			return false;
		}
		Object thisOrderField = getOrderField();
		Object otherOrderField = other.getOrderField();
		if (thisOrderField == null ? otherOrderField != null : !thisOrderField.equals(otherOrderField)) {
			return false;
		}
		Object thisOrder = getOrder();
		Object otherOrder = other.getOrder();
		return thisOrder == null ? otherOrder == null : thisOrder.equals(otherOrder);
	}

	protected boolean canEqual(Object other) {
		return other instanceof PageParameter;
	}

	@Override
    public int hashCode() {
		int prime = 59;
		int result = 1;
		result = result * 59 + getStart();
		result = result * 59 + getLimit();
		Object thisOrderField = getOrderField();
		result = result * 59 + (thisOrderField == null ? 43 : thisOrderField.hashCode());
		Object thisOrder = getOrder();
		result = result * 59 + (thisOrder == null ? 43 : thisOrder.hashCode());
		return result;
	}

	@Override
    public String toString() {
		return "PageParameter(start=" + getStart() + ", limit=" + getLimit() + ", orderField=" + getOrderField()
				+ ", order=" + getOrder() + ")";
	}

	public int getStart() {
		return this.start;
	}

	@ApiModelProperty(value = "每页数量，缺省值：10", example = "10")
	private int limit = 10;
	@ApiModelProperty("排序字段")
	private String orderField;
	@ApiModelProperty("排序方式")
	private String order;

	public int getLimit() {
		return this.limit;
	}

	public PageParameter(int start, int limit) {
		this.start = start;
		this.limit = limit;
	}

	@JsonIgnore
	public int getOffset() {
		return this.start * this.limit;
	}

	public String getOrderField() {
		return this.orderField;
	}

	public String getOrder() {
		return this.order;
	}

	public PageParameter() {
	}
}
